import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:sph_driver/AppConfig/Config.dart';
import 'package:sph_driver/FindGoods/ComplaintGoodsSecond.dart';

import '../AppConfig/RouteAct.dart';
import '../http/NoLoadingGetApi.dart';
import 'SubmitGoodsComplaint.dart';

class ComplaintGoods extends StatefulWidget {
  const ComplaintGoods({super.key, required this.dataMap});
  final Map dataMap;
  @override
  State<ComplaintGoods> createState() => _ComplaintGoodsState();
}

class _ComplaintGoodsState extends State<ComplaintGoods> {
  List titleList=["货源为违禁品/危险品/限运品等不能在本平台运输的物品","该货源存在不文明用语/广告","货主让我线下交易","货主推荐下载其他软件接单、支付运费、刷单、票等",
  "货源重复","货源信息与货主描述不一致","特殊要求/禁区未告知"];
  List dataList=[];
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    getPageAction();
  }
  void getPageAction(){
    NoLoadinggetApiManager.getData(
      context,
      "api/system/dev/dict/list",
      {'category':'BIZ','parentId':'1787648993406603266'},
          (responseData)  {
        setState(() {
          dataList=responseData['data'];
        });

      },
    );
  }

  @override
  Widget build(BuildContext context) {
    final screenSize = MediaQuery.of(context).size;
    return Scaffold(
      backgroundColor:Color.fromRGBO(248, 248, 248, 1),
      appBar: AppBar(
        title: Text("投诉",style: TextStyle(fontWeight: FontWeight.w300,fontSize: 16.sp),),
        centerTitle: true,
        backgroundColor: Colors.white,
      ),
      body: ListView(
        children: [
          Container(
            margin: EdgeInsets.only(left: 12.w,top: 8.h),
            child: Text("请选择投诉原因",style: TextStyle(color: Colors.black,fontSize: 16.sp,),),
          ),
          Container(
            margin: EdgeInsets.only(left: 10.w,right: 10.w,top: 8.h),
            padding: EdgeInsets.only(left: 8.w,right: 8.w),
            height: dataList.length*45.h,
            decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.all(Radius.circular(10))),
             child:  ListView.builder(
               itemCount: dataList.length,
               itemBuilder: (context, index) {
                 return GestureDetector(
                   child:Container(
                     padding: EdgeInsets.only(top: 8.h,bottom: 8.h),
                     child: Column(
                       children: [
                         Row(
                           mainAxisAlignment: MainAxisAlignment.spaceBetween,
                           children: [
                             Container(
                               width: screenSize.width-80.w,
                               child: Text(dataList[index]['dictLabel'],style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                             ),
                             Icon(Icons.arrow_forward_ios,color: MyColors.hintColor,),
                           ],
                         ),
                         if(index!=8)
                           Divider(height: 1.h,color: MyColors.backgreyColor,),
                       ],
                     ),
                   ) ,
                   onTap: (){
                     // if(index!=3) {
                     //   Navigator.push( context, FadeRoute(page:ComplaintGoodsSecond(index: index, dataMap: widget.dataMap,)));
                     //
                     // }else{


                     // }
                       NoLoadinggetApiManager.getData(
                         context,
                         "api/system/dev/dict/list",
                         {'category':'BIZ','parentId':dataList[index]['id']},
                             (responseData)  {
                           setState(() {
                             if(responseData['data'].isNotEmpty){
                               Navigator.push( context, FadeRoute(page:ComplaintGoodsSecond(index: index, dataMap: widget.dataMap, parentId: dataList[index]['id'],)));
                             }else{
                               Navigator.push( context, FadeRoute(page:SubmitGoodsComplaint(dataMap:widget.dataMap, parentId:dataList[index]['id'],)));

                             }
                           });

                         },
                       );
                   },
                 );


               },
          ),
          ),
        ],
      ),
    );
  }
}
